﻿using AgencyManagerSystem.AsmType;
using AgencyManagerSystem.Common;
using AgencyManagerSystem.Core;
using AgencyManagerSystem.DataFetcher;
using AgencyManagerSystem.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AgencyManagerSystem.Controllers
{
    public class ARController : ERPControllerBase
    {
        ERPArFetcher fetcher;
        public ARController() : base()
        {
            this.fetcher = new ERPArFetcher();
        }
        [HttpGet]
        //[RoleFlagAuthorizeAttribute(PolicyDomain.Retail, AppOpt.Exec)]
        public AsmArray<ERPAR> List(string jsonCondition, int pos, int size)
        {
            LogHelper.Debug(this.GetType().Name, String.Format("LIST:[RQS|{1}]{0}", jsonCondition, RequestIp));
            int cnt = 0;
            var BillReport = fetcher.List(Util.ConvertArrayFromJson<Condition>(jsonCondition), pos, size, out cnt);
            var bills = from item in BillReport  select item;
            var result = new AsmArray<ERPAR>() { Data = bills, Message = "操作成功", Result = AmsCode.Succ, Cnt = cnt };
            LogHelper.Debug(this.GetType().Name, String.Format("LIST:[RSP|{1}]{0}", Util.ConvertToJson(result), RequestIp));
            return result;
        }
    }
}
